﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="房产销冠, 房地产,卡考网络" />
    <meta name="description" content="上海卡考网络有限公司" />
    <title>房产销冠</title>
    <link rel="stylesheet" href="css/global.css" type="text/css" />
    <link rel="stylesheet" href="css/form.css" type="text/css" />
    <link href="bootstrap/iCheck-master/skins/minimal/orange.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css" />
    <link href="css/bootstrap-switch.css" rel="stylesheet" type="text/css" />
    <script src="http://dn-blqw.qbox.me/jq+bs+art.js" type="text/javascript"></script>
    <script src="js/jquery-form.js" type="text/javascript"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="bootstrap/iCheck-master/icheck.js"></script>
    <script type="text/javascript" src="js/bootstrap-switch.min.js"></script>
    <script type="text/javascript" src="js/WdatePicker.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/formValidator.js"></script>
    <script type="text/javascript" src="js/kk.js"></script>
    <link href="Scripts/webuploader/webuploader.css" rel="stylesheet" />
    <script src="Scripts/webuploader/webuploader.min.js" type="text/javascript"></script>
    <script src="Scripts/webuploader/webupload.expand.js" type="text/javascript"></script>
    <!--<script charset="utf-8" src="js/kindeditor-min.js"></script>-->
    <!--<script charset="utf-8" src="js/zh_CN.js"></script>-->
    <script type="text/javascript">
        $(document).ready(function () {
            initInput();
        });
        function initInput() {
            $('.lab112 :checkbox').iCheck({
                checkboxClass: 'icheckbox_minimal-orange',
                radioClass: 'iradio_minimal-orange',
                increaseArea: '20%' // optional
            });
            $('.lab112 :radio').iCheck({
                checkboxClass: 'icheckbox_minimal-orange',
                radioClass: 'iradio_minimal-orange',
                increaseArea: '20%' // optional
            });
        }
    </script>
    <script type="text/javascript">
        $(function () {
            //单图上传
            $("#btnUpLoadL").powerWebUpload({
                onComplete: function (data) {
                    //alert(JSON.stringify(data));
                    $('#imgBuilding').attr('src', data.filePath);
                    $("#picUrl").val(data.filePath);
                },
                PostbackHold: false
            });
            //多图上传
            var imgUrl = $("#productPic").val();
            $("#btnUpLoadList").powerWebUpload({
                onComplete: function (data) {
                    var str = "<div class='frompic2 fl'><div><img src='" + data.filePath + "'  width='105' height='77' /></div><div class='picdetline2'><img src='images/from_picclose.png' />删除</div>";
                    $("#imgList").append(str);

                    if (imgUrl != "" || imgUrl != null) {
                        alert(imgUrl);
                        imgUrl += "|";
                    }
                    imgUrl += data.filePath;
                    $("#productPic").val(imgUrl);

                },
                PostbackHold: true,
                ShowDownload: true
            });

        });

    </script>
</head>
<body style="background: #f1f1f1;">
    <div class="main01 pb50">
        <div class="fromtit1 clearfix">
            <h1 class="ff">商品管理》编辑商品</h1>
            <a href="#" class="gouback" onclick="f_Back()">返回</a>
        </div>
        <div class="fromtit2 clearfix">
            <h2 class="ff">基本信息</h2>
        </div>
        <div class="frommod clearfix">
            <form id="form1" action="">
                <input type="hidden" name="Kid" id="Kid" value="" />
                <table border="0" cellspacing="0" cellpadding="0" class="fromtab1">
                    <tr>
                        <th>有效期：&nbsp;</th>
                        <td>
                            <label class="lab112"><span id="beginTime">2015-01-16</span>至<span id="endTime">2015-06-08</span></label>
                        </td>
                    </tr>

                    <tr>
                        <th>商品分类：&nbsp;</th>
                        <td>
                            <select id="SelectCateogryKid" name="SelectCateogryKid" class="selall sel100 fl" style="margin-right: 11px;" onchange="UpdateCateogryKid(this.value)">
                                <option>--商品分类--</option>
                            </select>
                            <input type="hidden" id="categoryKid" name="categoryKid" value="0" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品名称：&nbsp;</th>
                        <td>
                            <input type="text" id="productName" name="productName" value="" class="inpall inp435" placeholder="请填写商品标题" maxlength="16" validatetype="*notempty" />
                        </td>
                    </tr>
                    <tr>
                        <th>详细说明：&nbsp;</th>
                        <td>
                            <textarea id="description" name="description" rows="" cols="" class="textall02 text435" placeholder="请输入详细说明" validatetype="*notempty"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th>缩略图：&nbsp;</th>
                        <td>
                            <div class="clearfix">
                                <div class="frompic1 fl" id="">
                                    <div>
                                        <img id="imgBuilding" width="105" height="77" />
                                    </div>
                                    <div class="picdetline">
                                        <img src="images/from_picclose.png" alt="" />
                                        删除
                                    </div>
                                </div>
                                <div class="fl">
                                    <div class="picinfos" id="btnUpLoadL">(请上传200px*150px的图片 )</div>
                                    <input type="hidden" id="picUrl" name="picUrl" value="" />
                                </div>
                            </div>
                        </td>
                    </tr>
                    <!--<tr>
                        <th>详情图：&nbsp;</th>
                        <td>
                            <div class="clearfix">
                                <div class="frompic1 fl">
                                    <div>
                                        <img src="images/build_pics.jpg" alt=""/>
                                    </div>
                                    <div class="picdetline">
                                        <img src="images/from_picclose.png" />
                                        删除
                                    </div>
                                </div>
                                <div class="fl">
                                    <div class="picinfos" id="btnUpLoadList">(请上传200px*150px的图片 )</div>
                                    <input type="hidden" id="productPic" name="productPic" value="" />
                                    <a href="#" class="picbtn">选择图片</a>
                                </div>
                            </div>
                        </td>
                    </tr>-->
                    <tr>
                        <th>需要积分：&nbsp;</th>
                        <td>
                            <input type="text" id="pointNum" name="pointNum" value="" class="inpall inp435" placeholder="请输入消耗积分" validatetype="*number" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品单价：&nbsp;</th>
                        <td>
                            <input type="text" id="productPrice" name="productPrice" value="" class="inpall inp435" placeholder="请输入商品实际价格" validatetype="*arithmetic" onkeyup="IsDouble(this)" />
                        </td>
                    </tr>
                    <tr>
                        <th>上架数量：&nbsp;</th>
                        <td>
                            <input type="text" id="stockNum" name="stockNum" value="" class="inpall inp435" placeholder="请输入上架数" validatetype="*number" />
                        </td>
                    </tr>
                    <tr>
                        <th>库存剩余：&nbsp;</th>
                        <td>
                            <input type="text" id="inventoryNum" name="inventoryNum" value="" class="inpall inp435" placeholder="请输入库存数" validatetype="*number" />
                        </td>
                    </tr>
                    <tr>
                        <th>排序：&nbsp;</th>
                        <td>
                            <input type="text" id="sort" name="sort" value="" class="inpall inp100" placeholder="排序" validatetype="*number" />
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td>
                            <label class="lab112">
                                <input type="radio" name="isSelect" value="0" />&nbsp;&nbsp;自动处理
                            </label>
                            <label class="lab112">
                                <input type="radio" name="isSelect" value="1" />&nbsp;&nbsp;手动处理
                            </label>
                            <input type="hidden" id="status" name="status" value="0" />
                        </td>
                    </tr>
                    <tr>
                        <th>商品来源：&nbsp;</th>
                        <td>
                            <input type="text" id="source" name="source" value="" class="inpall inp435" placeholder="请填写商品来源" maxlength="255" />
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td>
                            <div class="sinput">
                                <input type="button" class="Save" value="保存" onclick="f_SubmitSave()" />
                                <input type="button" class="Cancel" value="取消" onclick="f_Back()" />
                            </div>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            f_GetProduct();
        });
        $("input[name='isSelect']:eq(0)").on('ifChecked', function (event) {
            $("#source").parents("tr").show();
            $("#source").attr("validatetype", "*notempty");
            $("#status").val("0");
        });
        $("input[name='isSelect']:eq(1)").on('ifChecked', function (event) {
            $("#source").parents("tr").hide();
            $("#source").attr("validatetype", "notempty");
            $("#status").val("1");
        });
        // kk.api.add("a", "http://192.168.1.85:1060");
        //获取商品信息
        function f_GetProduct() {
            $kk.api.get("/PointProduct/Get", {
                Kid: GetUrlParam("kid")
            }, function (res) {
                $("#imgBuilding").attr("src", res.F_PicUrl);
                $("#picUrl").val(res.F_PicUrl);
                $("#Kid").val(res.Kid);
                $("#productName").val(res.F_ProductName);
                $("#pointNum").val(res.T_ExchangeRule.F_PointNum);
                $("#sort").val(res.F_Sort);
                $("#description").val(res.F_Description);
                $("#beginTime").text(res.T_ExchangeRule.F_BeginTime);
                $("#endTime").text(res.T_ExchangeRule.F_EndTime);
                $("input[name='isSelect'][value=" + res.T_ExchangeRule.F_Status + "]").attr("checked", true);
                $("input[name='isSelect'][value=" + res.T_ExchangeRule.F_Status + "]").parent().addClass("checked");
                $("#source").val(res.F_Source);
                if (res.T_ExchangeRule.F_Status == 0) {
                    $("#source").parents("tr").show();
                    $("#source").attr("validatetype", "*notempty");
                } else {
                    $("#source").parents("tr").hide();
                }
                $("#inventoryNum").val(res.F_InventoryNum);
                $("#stockNum").val(res.F_StockNum);
                $("#productPrice").val(res.F_ProductPrice);
                f_GetProductCategoryList(res.F_CategoryKid);
            });
        }

        function f_GetProductCategoryList(id) {
            $("#categoryKid").val(id);
            $kk.api.get("/ProductsCategory/GetList", function (data) {
                if (data != null) {
                    $.each(data, function (i, obj) {
                        if (obj.Kid == id) {
                            $("#SelectCateogryKid").append("<option selected value='" + obj.Kid + "'>" + obj.F_CategoryName + "</option>");
                        } else {
                            $("#SelectCateogryKid").append("<option value='" + obj.Kid + "'>" + obj.F_CategoryName + "</option>");
                        }
                    });
                }
            });
        }
        function UpdateCateogryKid(id) {
            $("#categoryKid").val(id);
        }

        //提交保存及验证
        $(".inpall").blur(function () {
            validate($(this));
        })
        $(document).ready(function () {
            validateInit("");
        });

        //保存
        function f_SubmitSave() {
            //表单验证
            if (!validate("#form1 input[validateType]")) {
                return;
            }
            //if (!$("#form1").form("validate")) {

            //    return false;
            //}
            // alert(JSON.stringify($("#form1:input[value],textarea").serializeArray()));
            if ($("input[name='isSelect']").eq(0).prop("checked")) {
                $("#status").val("0");
            } else {
                $("#status").val("1");
            }
            $kk.api.post("/PointProduct/UpdateField", $("#form1 :input[value],textarea").serializeArray(), function (res) {
                $kk.popup("保存成功", "success", 1500);

                setTimeout(function () { f_Back(); }, 1000);
            });
        }
        function f_Back() {
            self.location = document.referrer;
        }

        function IsDouble(obj) {
            obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
            obj.value = obj.value.replace(/^\./g, "");  //验证第一个字符是数字而不是.
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        }
    </script>


</body>
</html>
